Skip to main content

@pexip/signal

Interfaces

Type Aliases

Detach

Ƭ Detach: () => void

Type declaration

▸ (): void

A detach function to remove its observer from the Signal construct when it is called.

Example

interface Message {
type: string;
payload: any;
}
const messageSignal = createSignal<Message>();

const messageHandler = (message: Message) => {
logger.info({message});
};

const detachMessageSignal = connectedSignal.add(messageHandler);

// Wire the signal to WebSocket onMessage
ws.onmessage((message) => {
messageSignal.emit(message);
});

// Later there is no need to listen the message event, or the context is
about to be abandoned
// Call the detach function to remove the listener from messageSignal
detachMessageSignal();

Returns

void


ExtractSignalsState

Ƭ ExtractSignalsState<T>: { [K in keyof T]: T[K] extends Signal<infer S> ? S | undefined : undefined }

Type parameters

NameType
Textends Signal<unknown>[]

Observer

Ƭ Observer<T>: (subject: T) => void | Promise<void>

Type parameters

Name
T

Type declaration

▸ (subject): void | Promise<void>

Generic Observer function to handle the emitted signal.

Parameters
NameType
subjectT
Returns

void | Promise<void>


SignalVariant

Ƭ SignalVariant: "generic" | "behavior" | "replay"

Variant of available signal

Functions

combine

combine<T>(...signals): Signal<ExtractSignalsState<T>>

Type parameters

NameType
Textends Signal<unknown>[]

Parameters

NameType
...signalsT

Returns

Signal<ExtractSignalsState<T>>


createSignal

createSignal<T>(options?): Signal<T>

A function to create a new Signal

Example

const defaultSignal = createSignal<number>();

// Behavior Signal, always emitted with the latest value when added
const behaviorSignal = createSignal<number>({variant: 'behavior'});

// Replay Signal, replay the last values when added according to `bufferSize`
const replaySignal = createSignal<number>({variant: 'replay'});

Type parameters

NameType
Tundefined

Parameters

NameTypeDescription
optionsSignalOptionsSee SignalOptions

Returns

Signal<T>


setFlags

setFlags(newFlags): void

Parameters

NameType
newFlagsFlags

Returns

void


setLogger

setLogger(newLogger): void

Parameters

NameType
newLoggerLogger

Returns

void